package com.haizhi.crm.recommend.engine.impl;

import com.alibaba.fastjson.JSON;
import com.haizhi.crm.common.constant.RecStatus;
import com.haizhi.crm.common.exception.UnexpectedStatusException;
import com.haizhi.crm.recommend.context.RecRegister;
import com.haizhi.crm.recommend.engine.RecEngine;
import com.haizhi.crm.recommend.model.RecQo;
import com.haizhi.crm.recommend.model.RecVo;
import com.haizhi.crm.recommend.service.RecService;
import org.springframework.stereotype.Service;

/**
 * Created by chengmo on 2018/6/28.
 */
@Service
public class RecEngineImpl implements RecEngine {

    @Override
    public RecVo recommend(RecQo recQo) {
        try {
            RecService recService = RecRegister.getServiceImpl(recQo.getRecType());
            return recService.doRecommend(recQo);
        } catch (Exception e) {
            throw new UnexpectedStatusException(RecStatus.CALL_SERVICE_ERROR, e,
                    JSON.toJSONString(recQo));
        }
    }
}
